import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SensitivityDots extends StatelessWidget {
  /// 标签，比如 ["低", "中", "高"]
  final List<String> labels;

  /// 选中颜色
  final Color activeColor;

  /// 未选中颜色
  final Color inactiveColor;

  /// 控制器
  final RxInt selectedIndex;

  const SensitivityDots({
    super.key,
    required this.labels,
    required this.selectedIndex,
    this.activeColor = Colors.deepPurple,
    this.inactiveColor = Colors.grey,
  }) : assert(labels.length == 3, '目前仅支持3个标签');

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      return Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          // ===== 顶部标签 =====
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: List.generate(labels.length, (index) {
              return GestureDetector(
                onTap: () => selectedIndex.value = index,
                child: Text(
                  labels[index],
                  style: TextStyle(
                    fontSize: 16,
                    color: selectedIndex.value == index
                        ? activeColor
                        : inactiveColor,
                    fontWeight: selectedIndex.value == index
                        ? FontWeight.bold
                        : FontWeight.normal,
                  ),
                ),
              );
            }),
          ),
          const SizedBox(height: 10),

          // ===== 底部点状选择器 =====
          Stack
            (
            alignment: Alignment.center,
              children: [
            const Divider(thickness: 2,color: Colors.grey),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: List.generate(labels.length, (index) {
                final bool isSelected = selectedIndex.value == index;

                return GestureDetector(
                  onTap: () => selectedIndex.value = index,
                  child: Container(
                    width: 24,
                    height: 24,
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      color: isSelected ? activeColor : Colors.white,
                      border: Border.all(
                        color: isSelected ? activeColor : Colors.white,
                        width: 2,
                      ),
                    ),
                    child: isSelected
                        ? const Icon(
                            Icons.check,
                            size: 16,
                            color: Colors.white,
                          )
                        : null,
                  ),
                );
              }),
            )
          ]),
        ],
      );
    });
  }
}
